package com.cloudbroker.openapi.controller;

import com.cloudbroker.bcs.common.util.DateTimeUtil;
import com.cloudbroker.bcs.platform.dav.bizapi.service.operate.result.OperateGetFansBackResult;
import com.cloudbroker.bcs.platform.dav.bizapi.service.operate.result.OperateGetFansData;
import com.cloudbroker.bcs.platform.dav.bizapi.service.operate.vo.OperateGetFansForm;
import com.cloudbroker.bcs.platform.dav.bizapi.t2service.operate.OperateFansT2BizService;
import com.cloudbroker.bcs.platform.dav.common.ext.annotation.SaveLog;
import com.cloudbroker.bcs.platform.dav.common.util.WhiteListFileUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.cloudbroker.bcs.platform.dav.common.util.RequestUtil.getSingleParameterMapForBody;

/**
 * Created by wangxu13798 on 2016/8/30.
 */
@Controller
public class OperateFansController {
    @Resource
    private OperateFansT2BizService operateFansT2BizService;

    @ResponseBody
    @RequestMapping("/func_operate_fans_export")
    @SaveLog(remark = "运营端查询粉丝列表导出")
    public Map<String, Object> funcOperateFansExport(HttpServletRequest request, HttpServletResponse response, String jsonpcallback) {
        OperateGetFansForm form = getSingleParameterMapForBody(request, OperateGetFansForm.class);
        String fileName,sheetName;
        Map<String,String> map = new HashMap<>();
        if("0".equals(form.getFans_type())){
            fileName = "黑名单列表-" + DateTimeUtil.toString(new Date(), DateTimeUtil.FORMAT_YYYYMMDD);
            sheetName = "黑名单列表";
            map.put("customer_id","用户编号");
            map.put("customer_name","粉丝昵称");
            map.put("mobile","手机号");
            map.put("branch_name","归属");
            map.put("total_amount","打赏总金额");
            map.put("reply_amount","评论数");
            map.put("upvote_amount","点赞数");
        }else {
            fileName = "用户列表-" + DateTimeUtil.toString(new Date(), DateTimeUtil.FORMAT_YYYYMMDD);
            sheetName = "用户列表";
            map.put("customer_id","用户编号");
            map.put("customer_name","粉丝昵称");
            map.put("mobile","手机号");
            map.put("branch_name","归属");
            map.put("register_time","注册时间");
            map.put("total_amount","消费金额/金币");
            map.put("question_amount","提问/次");
            map.put("reply_amount","评论/次");
            map.put("upvote_amount","点赞/次");
            map.put("gag_flag","禁言状态");
        }
        OperateGetFansBackResult operateGetFansBackResult = operateFansT2BizService.funcOperateFansExport(form);
        List<OperateGetFansData> list = operateGetFansBackResult.getData_list();
        WhiteListFileUtil.exportExcel(response,fileName,list,map,sheetName);
        return null;
    }
}
